package com.tool.btn;

import java.awt.Color;
import java.awt.event.MouseEvent;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.swing.SwingConstants;

import org.come.Frame.ZhuFrame;
import org.come.Jpanel.PetTujianJpanel;
import org.come.Jpanel.TaobaoCourtSplendidJpanel;
import org.come.bean.BuyShopBean;
import org.come.entity.RoleSummoning;
import org.come.model.Eshop;
import org.come.socket.Agreement;
import org.come.socket.SendMessageUntil;
import org.come.until.CutButtonImage;
import org.come.until.FormsManagement;
import org.come.until.GoodsListFromServerUntil;
import org.come.until.GsonUtil;
import org.come.until.Util;

import com.gl.util.Xy2Util;
import com.tool.role.RoleData;
import com.tool.role.RoleTX;
import com.tool.tcpimg.UIUtils;
import com.updateNew.MyIsif;

public class PetTujianSpecificBtn extends MoBanBtn {

    private int caozuo;
    private PetTujianJpanel petTujianJpanel;
    private int petId;
    public PetTujianSpecificBtn(String iconpath, int type, String text, int caozuo) {
        super(iconpath, type);
        this.caozuo = caozuo;
        this.setText(text);
        setFont(UIUtils.TEXT_FONT);
        if (caozuo >= 3 && caozuo <= 5) {
            setForeground(Color.yellow);
        } else {
            setForeground(Color.white);
        }
        setVerticalTextPosition(SwingConstants.CENTER);
        setHorizontalTextPosition(SwingConstants.CENTER);
        // TODO Auto-generated constructor stub
    }

    public PetTujianSpecificBtn(String iconpath, int type, Color[] colors, String text, int caozuo) {
        // TODO Auto-generated constructor stub
        super(iconpath, type, colors);
        this.caozuo = caozuo;
        this.setText(text);
        setFont(UIUtils.TEXT_FONT2);
        setVerticalTextPosition(SwingConstants.CENTER);
        setHorizontalTextPosition(SwingConstants.CENTER);

    }

    public PetTujianSpecificBtn(String iconpath, int type, String text, int caozuo,
    		PetTujianJpanel petTujianJpanel,int petId) {
        super(iconpath, type);
        this.caozuo = caozuo;
        this.petId = petId;
        this.petTujianJpanel = petTujianJpanel;
        this.setText(text);
        if (caozuo > 19 && caozuo < 22) {
            setFont(UIUtils.TEXT_HY16);
            setForeground(Color.white);
        } else {
            setFont(UIUtils.TEXT_FONT2);
            setForeground(Color.white);
        }
        setVerticalTextPosition(SwingConstants.CENTER);
        setHorizontalTextPosition(SwingConstants.CENTER);
        // TODO Auto-generated constructor stub
    }

    @Override
    public void chooseyes() {
        // TODO Auto-generated method stub

    }

    @Override
    public void chooseno() {
        // TODO Auto-generated method stub

    }

    @Override
    public void nochoose(MouseEvent e) {
    		if (caozuo == 11) {// 首页
    			petTujianJpanel.setNowpage(1);
    			petTujianJpanel.refreshDbgSplendid(getPetList(), petTujianJpanel.getNowpage());
    		} else if (caozuo == 12) {// 上一页
    			petTujianJpanel.setNowpage(petTujianJpanel.getNowpage() - 1 <= 1 ? 1
    					: petTujianJpanel.getNowpage() - 1);
    			// 刷新界面
    			petTujianJpanel.refreshDbgSplendid(getPetList(), petTujianJpanel.getNowpage());
    		} else if (caozuo == 13) {// 下一页
    			// 总页数
    			int totalpage = getPetList().size() / 5 + (getPetList().size() % 5 == 0 ? 0 : 1);
    			petTujianJpanel.setNowpage(petTujianJpanel.getNowpage() + 1 >= totalpage ? totalpage
    					: petTujianJpanel.getNowpage() + 1);
    			// 刷新界面
    			
    			petTujianJpanel.refreshDbgSplendid(getPetList(), petTujianJpanel.getNowpage());
    		} else if (caozuo == 14) {// 末页
    			// 总页数
    			int totalpage = getPetList().size() / 5 + (getPetList().size() % 5 == 0 ? 0 : 1);
    			petTujianJpanel.setNowpage(totalpage);
    			// 刷新界面
    			petTujianJpanel.refreshDbgSplendid(getPetList(), petTujianJpanel.getNowpage());
    		}  else if (caozuo == 15) {// 
    			// 检索
    			petTujianJpanel.selectPet();
    		}  else if (caozuo == 16) {// 合成
    			String petid = petTujianJpanel.getPetids()[this.petId];
    			if(Integer.parseInt(petTujianJpanel.getPetdebrisNum(petid))>=30) {
    				String sendmes = Agreement.getAgreement().userAgreement("合成="+petid);
    				SendMessageUntil.toServer(sendmes);
    			}else {
    				ZhuFrame.getZhuJpanel().addPrompt2("碎片不足30个，无法合成");
        			return;
    			}
    			petTujianJpanel.refreshDbgSplendid(getPetList(), petTujianJpanel.getNowpage());
      		}  else if (caozuo == 17) {
      			ZhuFrame.getZhuJpanel().pettext();
      			String petid = petTujianJpanel.getPetids()[this.petId];
      			RoleSummoning pet = new RoleSummoning();
      			if(Xy2Util.addpetList.size()>0) {
      				for(RoleSummoning summoning:Xy2Util.addpetList) {
      					if(summoning.getSummoningid().equals(petid)) {
      						pet = summoning;
      					}
      				}
      			}
      			if(pet!=null) {
      				ZhuFrame.getZhuJpanel().creatpettext(pet);
      			}
      		} 
       
    }

    /** 购买 */
    public void BUY(Eshop eshop) {
        if (!Util.canBuyOrno) {
            ZhuFrame.getZhuJpanel().addPrompt2("背包没有解锁!");
            return;
        }
        if (RoleData.getRoleData().getPackRecord().isTX(-Integer.parseInt(eshop.getEshopiid()) + "")) {
            ZhuFrame.getZhuJpanel().addPrompt2("你已拥有该特效");
            return;
        }
        if ((RoleData.getRoleData().getLoginResult().getCodecard().compareTo(new BigDecimal(eshop.getEshopprice()))) >= 0) {
            BuyShopBean bean = new BuyShopBean();
            bean.setAte(0);
            bean.setCd(eshop.getEshopid());
            bean.setSum(1);
            String senmes = Agreement.getAgreement().nbuyAgreement(GsonUtil.getGsonUtil().getgson().toJson(bean));
            SendMessageUntil.toServer(senmes);
        } else {
            ZhuFrame.getZhuJpanel().addPrompt2("没有足够的仙玉!");
        }

    }

    public List<RoleSummoning> getPetList(){
    	List<RoleSummoning> petlist = Xy2Util.addpetList;
		return petlist;
    }
}
